home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / phillip2 / xdisplay.c < prev   
Encoding:
C/C++ Source or Header  |  1993-05-14  |  23.4 KB  |  915 lines

  1.  
  2.  
  3.    /**************************************************
  4.    *
  5.    *   file d:\cips\display.c
  6.    *
  7.    *   Functions: This file contains
  8.    *      display_image
  9.    *      display_image_portion
  10.    *      display_menu_for_display_image
  11.    *      map_16_shades_of_gray
  12.    *      map_64_shades_of_gray
  13.    *      transform_the_colors
  14.    *
  15.    *   Purpose:
  16.    *      These functions display images on a the
  17.    *      monitor.
  18.    *
  19.    *   External Calls:
  20.    *      rtiff.c - read_tiff_image
  21.    *      cips.c - my_clear_text_screen
  22.    *      hist.c - zero_histogram
  23.    *               calculate_histogram
  24.    *               perform_histogram_equalization
  25.    *               display_histogram
  26.    *
  27.    *   Modifications:
  28.    *      17 June 1987 - created
  29.    *      August 1990 - extension modifications for use
  30.    *          in the C Image Processing System.
  31.    *
  32.    ***************************************************/
  33.  
  34.  
  35. #include "cips.h"
  36.  
  37.  
  38.  
  39.  
  40.  
  41.    /***************************
  42.    *
  43.    *   display_image(...
  44.    *
  45.    ****************************/
  46.  
  47.  
  48. display_image(file_name, image, il, ie, ll, le,
  49.               image_header, monitor_type, 
  50.               color_transform, invert, image_colors, 
  51.               display_colors, show_hist, title)
  52.    char    color_transform[],
  53.            file_name[],
  54.            monitor_type[],
  55.            title[];
  56.    int     display_colors,
  57.            image_colors,
  58.            invert,
  59.            il,
  60.            ie,
  61.            ll,
  62.            le,
  63.            show_hist;
  64.    short   image[ROWS][COLS];
  65.    struct  tiff_header_struct *image_header;
  66. {
  67.    char  channels[80],
  68.          response[80];
  69.  
  70.    int   a,
  71.          b,
  72.          c,
  73.          channel,
  74.          count,
  75.          display_mode,
  76.          dx_offset,
  77.          dy_offset,
  78.          key,
  79.          horizontal,
  80.          len,
  81.          max_horizontal,
  82.          max_vertical,
  83.          not_finished,
  84.          q,
  85.          r,
  86.          vertical,
  87.          x_offset,
  88.          y_offset;
  89.  
  90.    unsigned int block,
  91.                 color,
  92.                 i,
  93.                 j,
  94.                 x,
  95.                 y;
  96.    unsigned long histogram[256], new_hist[256];
  97.  
  98.  
  99.      /**********************************************
  100.      *
  101.      *   If you want to display the histogram and 
  102.      *   do not want to perform hist equalization, 
  103.      *   then zero the histogram for calculations.
  104.      *
  105.      **********************************************/
  106.  
  107.    if(  (show_hist == 1)   &&
  108.         (color_transform[0] != 'H'))
  109.       zero_histogram(histogram);
  110.  
  111.    not_finished = 1;
  112.    while(not_finished){
  113.  
  114.  
  115.       if(display_colors == 16){
  116.          if(monitor_type[0] == 'V'){
  117.             horizontal   = 4;
  118.         vertical = 6;
  119.         display_mode = _VRES16COLOR; /* MSC 6.0 */
  120.          }  /* ends if V */
  121.          if(monitor_type[0] == 'E'){
  122.             horizontal   = 3;
  123.             vertical     = 6;
  124.             display_mode = _ERESCOLOR; /* MSC 6.0 */
  125.          }  /* ends if E */
  126.  
  127.       }  /* ends if colors == 16 */
  128.  
  129.       else{
  130.          horizontal   = 2;
  131.          vertical     = 2;
  132.          display_mode = _MAXCOLORMODE; /* MSC 6.0 */
  133.       }
  134.  
  135.         /********************************************
  136.         *
  137.         *   Somehow, my dx and dy offsets are 
  138.         *   backwards from my horizontal and vertical 
  139.         *   variables. Trying to center the images 
  140.         *   on the screen. March 21 1992
  141.         *
  142.         ********************************************/
  143.  
  144.       max_horizontal = (image_header->image_length+50)
  145.                        /COLS;
  146.       max_vertical   = (image_header->image_width+50)
  147.                        /ROWS;
  148.  
  149.       dy_offset = ((horizontal-max_horizontal)/2)
  150.                   *COLS + 50;
  151.       dx_offset = ((vertical-max_vertical)/2)
  152.                   *ROWS + 20;
  153.  
  154.       if(max_horizontal > horizontal) dy_offset = 0;
  155.       if(max_vertical > vertical)     dx_offset = 0;
  156.  
  157.       if(horizontal > max_horizontal) 
  158.          horizontal = max_horizontal;
  159.       if(vertical > max_vertical)     
  160.          vertical   = max_vertical;
  161.  
  162.  
  163.         /****************************************
  164.         *
  165.         *   If color transform wants histogram
  166.         *   equalization, then read in the
  167.         *   image arrays and calculate the
  168.         *   histogram.   Zero both the histogram
  169.         *   and the new_hist.  You will need the
  170.         *   new_hist if you want to display the
  171.         *   equalized hist.
  172.         *
  173.         *****************************************/
  174.  
  175.       if(color_transform[0] == 'H'){
  176.          count = 1;
  177.          zero_histogram(histogram);
  178.          zero_histogram(new_hist);
  179.          for(a=0; a<vertical; a++){
  180.             for(b=0; b<horizontal; b++){
  181.  
  182.                x = a*COLS;
  183.                y = b*ROWS;
  184.  
  185.                printf(
  186.                   "\nDISPLAY> Calculating histogram");
  187.                printf(" %d of %d",
  188.                   count,vertical*horizontal);
  189.                count++;
  190.                read_tiff_image(file_name, image, il+y,
  191.                             ie+x, ll+y, le+x);
  192.                calculate_histogram(image, histogram);
  193.  
  194.             }  /* ends loop over b */
  195.          }  /* ends loop over a */
  196.       }  /* ends if display_mode == H */
  197.  
  198.  
  199.         /* set graphics mode */
  200.  
  201.    _setvideomode(display_mode); /* MSC 6.0 */
  202.    if(display_colors == 16) 
  203.       map_16_shades_of_gray(display_mode);
  204.    if(display_colors == 256) 
  205.       map_64_shades_of_gray();
  206.  
  207.  
  208.         /****************************************
  209.         *
  210.         *   Loop over this size and
  211.         *   read and display ROWSxCOLS arrays.
  212.         *
  213.         *   If you want to show the histogram AND
  214.         *   do not want to do hist equalization
  215.         *   then calculate the hist from the
  216.         *   original image array.
  217.         *
  218.         *   If you want to do hist equalization
  219.         *   then calculate the new_hist AFTER
  220.         *   the image has been equalized by the
  221.         *   the transform_the_colors function.
  222.         *
  223.         *   NOTE: Remember that the function
  224.         *   transform_the_colors changes the
  225.         *   gray shade values in image array.
  226.         *
  227.         *****************************************/
  228.  
  229.         /*****************************************
  230.         *
  231.         *   These statements place a gray 
  232.         *   background across the display area of 
  233.         *   a VGA screen.  This reduces the 
  234.         *   contrast between the screen background 
  235.         *   and the images you display. This makes 
  236.         *   it easier to take photos.
  237.         *
  238.         *******************************************/
  239.  
  240.       _setlinestyle(0xFFFF);
  241.       _setcolor(10);
  242.       for(i=0; i<640;i++){
  243.          _moveto(i, 0);
  244.          _lineto(i, 480);
  245.       }
  246.  
  247.       for(a=0; a<vertical; a++){
  248.          for(b=0; b<horizontal; b++){
  249.  
  250.             x = a*COLS;
  251.             y = b*ROWS;
  252.             read_tiff_image(file_name, image, il+y,
  253.                             ie+x, ll+y, le+x);
  254.             if(  (show_hist == 1)  &&
  255.                  (color_transform[0] != 'H'))
  256.                calculate_histogram(image, histogram);
  257.  
  258.             transform_the_colors(image, 
  259.                                  color_transform,
  260.                                  display_colors,
  261.                                  image_colors, 
  262.                                  histogram,
  263.                                  horizontal, 
  264.                                  vertical);
  265.  
  266.             if(color_transform[0] == 'H')
  267.                calculate_histogram(image, new_hist);
  268.           display_image_portion(image, x+dx_offset,
  269.                                 y+dy_offset, 
  270.                                 display_colors,
  271.                                 image_colors, invert);
  272.          }        /* ends loop over b */
  273.       }        /* ends loop over a */
  274.  
  275.           /*******************************************
  276.           *
  277.           *   Put in these statements to print a title 
  278.           *   at the bottom of the display.  This is 
  279.           *   nice for taking photos or articles 
  280.           *   because it tells the reader what you 
  281.           *   are trying to do.
  282.           *
  283.           ********************************************/
  284.  
  285.       _settextcolor(10);
  286.       _setbkcolor(1L);
  287.       len = strlen(title);
  288.       len = 40 - (len/2);
  289.       _settextposition(28, len);
  290.       _outtext(title);
  291.  
  292.          /***************************
  293.          *
  294.          *   if show_hist == 1 then
  295.          *   display the histogram
  296.          *   in the lower right hand
  297.          *   corner of screen
  298.          *
  299.          *   If hist equalization was
  300.          *   performed then show the
  301.          *   new_hist.  If it wasn't
  302.          *   done then show the original
  303.          *   histogram.
  304.          *
  305.          ****************************/
  306.  
  307.       if(show_hist == 1){
  308.          if(monitor_type[0] == 'V')
  309.             y_offset = 470;
  310.          if(monitor_type[0] == 'E')
  311.             y_offset = 310;
  312.          x_offset = 380;
  313.          if(color_transform[0] == 'H')
  314.             display_histogram(new_hist, x_offset,
  315.                    y_offset, 5, 9);
  316.          else{
  317.             display_histogram(histogram, x_offset,
  318.                    y_offset, 5, 9);
  319.                /* xtra stuff for cips9
  320.             display_histogram(histogram, 45,
  321.                    370, 5, 9); */
  322.  
  323.                /*********************************
  324.                *
  325.                *   Change to show smoothed
  326.                *   histogram next to the regular
  327.                *   histogram.
  328.                *
  329.                **********************************/
  330.  
  331.                /* xtra stuff for cips9
  332.             smooth_histogram(histogram);
  333.             display_histogram(histogram, 345,
  334.                    370, 5, 9); */
  335.          }
  336.       }
  337.  
  338.       gets(response);
  339.       printf("\nEnter 0 to quit 1 to do again");
  340.       get_integer(¬_finished);
  341.  
  342.           /* set display back to text mode */
  343.       my_clear_text_screen();
  344.  
  345.  
  346.    }  /* ends while not_finished  */
  347.  
  348. }  /* ends main  */
  349.  
  350.  
  351.  
  352.  
  353.    /***********************************************
  354.    *
  355.    *   display_menu_for_display_image(
  356.    *
  357.    ************************************************/
  358.  
  359. display_menu_for_display_image(image_colors, 
  360.                               display_colors,
  361.                               invert, color_transform,
  362.                               monitor_type,
  363.                               show_hist)
  364.    char color_transform[], monitor_type[];
  365.    int  *invert, *image_colors, 
  366.         *display_colors, *show_hist;
  367. {
  368.    char response[80];
  369.    int  int_response, not_finished, r;
  370.  
  371.    not_finished = 1;
  372.    while(not_finished){
  373.       printf("\n\nDISPLAY> Enter choice "
  374.              "(0 for no change) ");
  375.       printf("\nDISPLAY> 1. Invert is %d (1=on 0=off)",
  376.              *invert);
  377.       printf("\nDISPLAY> 2. Color Transform-- %s",
  378.              color_transform);
  379.       printf("\nDISPLAY> 3. Input image has %d colors",
  380.              *image_colors);
  381.       printf("\nDISPLAY> 4. Display will show %d colors",
  382.              *display_colors);
  383.       printf("\nDISPLAY> 5. Monitor type is %s",
  384.              monitor_type);
  385.       printf("\nDISPLAY> 6. Histogram is %d", 
  386.              *show_hist);
  387.       printf("  (1=show 0=don't show)");
  388.       printf("\nDISPLAY> _\b");
  389.       get_integer(&r);
  390.  
  391.       if(r == 0){
  392.          not_finished = 0;
  393.       }
  394.  
  395.       if(r == 1){
  396.          printf("\nDISPLAY> Enter 1 for invert on");
  397.          printf(" 0 for invert off");
  398.          printf("\nDISPLAY> ___");
  399.          get_integer(&int_response);
  400.          *invert = int_response;
  401.       }  /* ends if r == 1 */
  402.  
  403.       if(r == 2){
  404.          printf("\nDISPLAY> Enter the new color "
  405.                 "transform mode ");
  406.          printf("\nDISPLAY> (S) Straight mode");
  407.          printf("   (H) Histogram Equalization");
  408.          printf("\nDISPLAY> _\b");
  409.          gets(response);
  410.          if((response[0] == 'S') ||
  411.             (response[0] == 's'))
  412.                strcpy(color_transform, 
  413.                       "Straight mode");
  414.          else
  415.                strcpy(color_transform,
  416.                 "Histogram Equalization mode");
  417.       }  /* ends if r == 2  */
  418.  
  419.       if(r == 3){
  420.          printf("\nDISPLAY> Enter the number "
  421.                 "of colors");
  422.          printf(" in the input image");
  423.          printf("\nDISPLAY> ___");
  424.          get_integer(&int_response);
  425.          *image_colors = int_response;
  426.       }  /* ends if r == 3 */
  427.  
  428.       if(r == 4){
  429.          printf(
  430.           "\nDISPLAY> Enter the number of colors "
  431.           "for the display");
  432.          printf("\nDISPLAY> ___");
  433.          get_integer(&int_response);
  434.          *display_colors = int_response;
  435.       }  /* ends if r == 4 */
  436.  
  437.       if(r == 5){
  438.          printf("\nDISPLAY> Enter the new monitor type");
  439.          printf("\nDISPLAY> (E) EGA   (V) VGA");
  440.          printf("   (C) CGA   (M) Monochrome");
  441.          printf("\nDISPLAY> _\b");
  442.          gets(response);
  443.          if((response[0] == 'E') ||
  444.             (response[0] == 'e'))
  445.             strcpy(monitor_type, "EGA");
  446.       if((response[0] == 'V') ||
  447.          (response[0] == 'v'))
  448.             strcpy(monitor_type, "VGA");
  449.       if((response[0] == 'C') ||
  450.          (response[0] == 'c'))
  451.             strcpy(monitor_type, "CGA");
  452.       if((response[0] == 'M') ||
  453.          (response[0] == 'm'))
  454.             strcpy(monitor_type, "Monochrome");
  455.       }  /* ends if r == 5  */
  456.  
  457.       if(r == 6){
  458.          printf(
  459.             "\nDISPLAY> Enter 1 for show histogram "
  460.             "0 for don't");
  461.          printf("\nDISPLAY> ___");
  462.          get_integer(&int_response);
  463.          *show_hist = int_response;
  464.       }  /* ends if r == 6 */
  465.  
  466.    }  /* ends while not_finished  */
  467. }  /* ends display_menu  */
  468.  
  469.  
  470.  
  471.  
  472.    /********************************
  473.    *
  474.    *   display_image_portion(...
  475.    *
  476.    *********************************/
  477.  
  478. display_image_portion(image, x, y, display_colors, 
  479.                       image_colors, invert)
  480.    int      invert, display_colors, image_colors;
  481.    short    image[ROWS][COLS];
  482.    unsigned int x, y;
  483. {
  484.    unsigned int color, i, j;
  485.  
  486.       if(invert == 1){
  487.         for(i=0; i<ROWS; i++)
  488.            for(j=0; j<COLS; j++)
  489.               image[i][j] = (display_colors-1)
  490.                              - image[i][j];
  491.       }  /* ends if invert == 1 */
  492.  
  493.       for(i=0; i<ROWS; i++){
  494.          for(j=0; j<COLS; j++){
  495.  
  496.         _setcolor(image[i][j]);
  497.         _setpixel(j+x, i+y);
  498. /*****
  499. my_set_pixel(j+x, i+y, image[i][j]);
  500. ******/
  501.  
  502.          }  /* ends loop over j  */
  503.       }     /* ends loop over i  */
  504.  
  505. }  /* ends display_image_portion  */
  506.  
  507.  
  508.  
  509.  
  510.  
  511.    /**********************************************
  512.    *
  513.    *   map_16_shades_of_gray(...
  514.    *
  515.    *   This function maps 16 shades of gray into
  516.    *   the first 16 color indices.  This allows
  517.    *   you to display a true "black and white"
  518.    *   image on a color monitor.
  519.    *
  520.    *********************************************/
  521.  
  522. map_16_shades_of_gray(display_mode)
  523.    int display_mode;
  524. {
  525.    /* all MSC 6.0 statements */
  526. _setvideomode(display_mode);
  527. _remappalette(0,  0x000000L);
  528. _remappalette(1,  0x040404L);
  529. _remappalette(2,  0x080808L);
  530. _remappalette(3,  0x0c0c0cL);
  531. _remappalette(4,  0x101010L);
  532. _remappalette(5,  0x141414L);
  533. _remappalette(6,  0x181818L);
  534. _remappalette(7,  0x1c1c1cL);
  535. _remappalette(8,  0x202020L);
  536. _remappalette(9,  0x242424L);
  537. _remappalette(10, 0x282828L);
  538. _remappalette(11, 0x2c2c2cL);
  539. _remappalette(12, 0x303030L);
  540. _remappalette(13, 0x343434L);
  541. _remappalette(14, 0x383838L);
  542. _remappalette(15, 0x3f3f3fL);
  543. }
  544.  
  545.  
  546.  
  547.  
  548.    /*********************************************
  549.    *
  550.    *   transform_the_colors(...
  551.    *
  552.    *   This function transforms the gray shades
  553.    *   in the image array for display.  It can either
  554.    *   do it in straight mode by multiplying or
  555.    *   dividing or it can do it with hist
  556.    *   equalization by calling the function
  557.    *   perform_histogram_equalization.
  558.    *
  559.    *************************************************/
  560.  
  561. transform_the_colors(image, color_transform,
  562.                      display_colors, image_colors,
  563.                      histogram, horizontal,
  564.                      vertical)
  565.    char   color_transform[];
  566.    int    display_colors, horizontal,
  567.           image_colors, vertical;
  568.    short  image[ROWS][COLS];
  569.    unsigned long histogram[];
  570. {
  571.    int         color, i, j;
  572.    float new_grays, area;
  573.    unsigned long x;
  574.  
  575.    if(color_transform[0] == 'S'){
  576.       for(i=0; i<ROWS; i++){
  577.          for(j=0; j<COLS; j++){
  578.  
  579.             if( (display_colors == 16) &&
  580.                 (image_colors  == 256))
  581.                color = image[i][j]/16;
  582.             if( (display_colors == 16) &&
  583.                 (image_colors  == 16))
  584.                color = image[i][j];
  585.             if( (display_colors == 256) &&
  586.                 (image_colors  == 256))
  587.                color = image[i][j];
  588.             if( (display_colors == 256) &&
  589.                 (image_colors  == 16))
  590.                color = image[i][j]*16;
  591.  
  592.             image[i][j] = color;
  593.  
  594.          }  /* ends loop over j        */
  595.       }        /* ends loop over i        */
  596.    }  /* ends if transform is straight */
  597.  
  598.    if(color_transform[0] == 'H'){
  599.  
  600.       area      = ((long)(vertical)) *
  601.                   ((long)(horizontal));
  602.       area      = area*10000.0;
  603.       new_grays = display_colors;
  604.  
  605.       perform_histogram_equalization(image, histogram,
  606.                                      new_grays, area);
  607.  
  608.    }  /* ends if transform is hist equalization */
  609.  
  610. }  /* ends transform_the_colors */
  611.  
  612.  
  613.  
  614.  
  615.    /**********************************
  616.    *
  617.    *   NOT USED IN CIPS
  618.    *
  619.    *   Modes for the SigmaVGA Legend
  620.    *               (hex)
  621.    *   10 - 640x350x64?
  622.    *   12 - 640x480x16
  623.    *   29 - 800x600x16
  624.    *   30 - 800x600x256
  625.    *   38 - 1024x768x256
  626.    *
  627.    ***********************************/
  628.  
  629. my_set_video_mode()
  630. {
  631.  
  632.    union REGS regs;
  633.  
  634.    regs.h.al = 0x29; /* mode */
  635.    regs.h.ah = 0x00;
  636.    int86(0x10, ®s, ®s);
  637.  
  638.  
  639. }  /* ends my_set_video_mode */
  640.  
  641.  
  642.    /*************************
  643.    *
  644.    *   NOT USED IN CIPS
  645.    *
  646.    *************************/
  647.  
  648. my_set_pixel(x, y, color)
  649.    unsigned int x, y, color;
  650. {
  651.  
  652. union REGS regs;
  653. char  r[80];
  654. int i;
  655.  
  656.    regs.h.ah = 0x0c;
  657.    regs.x.dx = y;
  658.    regs.x.cx = x;
  659.    regs.h.al = color;
  660.    regs.h.bh = 0x00;
  661.  
  662.    int86(0x10, ®s, ®s);
  663.  
  664. }  /* ends my_set_pixel */
  665.  
  666.  
  667.  
  668.  
  669.    /*************************
  670.    *
  671.    *   NOT USED IN CIPS
  672.    *
  673.    *************************/
  674.  
  675. my_set_colors()
  676. {
  677.  
  678.  union REGS regs;
  679.  int i;
  680.  
  681.  
  682.       /*********************
  683.          this works for 256 color modes
  684.          it does not work for 16 color modes
  685.       *********************/
  686.  
  687.    _asm{
  688.  
  689.       mov   ax,0030h ; set graphics mode 30h=800x600x256
  690.       int   10h
  691.  
  692.       mov ax,0h
  693.       mov dx,3c8h ; select first DAC register
  694.  
  695.       out dx,al
  696.       inc dx          ; set DAC data register
  697.  
  698.       mov al,0h
  699.       out dx,al
  700.       out dx,al
  701.       out dx,al
  702.  
  703.       mov al,4h
  704.       out dx,al
  705.       out dx,al
  706.       out dx,al
  707.  
  708.       mov al,8h
  709.       out dx,al
  710.       out dx,al
  711.       out dx,al
  712.  
  713.       mov al,ch
  714.       out dx,al
  715.       out dx,al
  716.       out dx,al
  717.  
  718.       mov al,10h
  719.       out dx,al
  720.       out dx,al
  721.       out dx,al
  722.  
  723.       mov al,14h
  724.       out dx,al
  725.       out dx,al
  726.       out dx,al
  727.  
  728.       mov al,18h
  729.       out dx,al
  730.       out dx,al
  731.       out dx,al
  732.  
  733.       mov al,1ch
  734.       out dx,al
  735.       out dx,al
  736.       out dx,al
  737.  
  738.       mov al,20h
  739.       out dx,al
  740.       out dx,al
  741.       out dx,al
  742.  
  743.       mov al,24h
  744.       out dx,al
  745.       out dx,al
  746.       out dx,al
  747.  
  748.       mov al,28h
  749.       out dx,al
  750.       out dx,al
  751.       out dx,al
  752.  
  753.       mov al,2ch
  754.       out dx,al
  755.       out dx,al
  756.       out dx,al
  757.  
  758.       mov al,30h
  759.       out dx,al
  760.       out dx,al
  761.       out dx,al
  762.  
  763.       mov al,34h
  764.       out dx,al
  765.       out dx,al
  766.       out dx,al
  767.  
  768.       mov al,38h
  769.       out dx,al
  770.       out dx,al
  771.       out dx,al
  772.  
  773.       mov al,3ch
  774.       out dx,al
  775.       out dx,al
  776.       out dx,al
  777.    } /* ends asm */
  778.  
  779.  
  780.  
  781. }  /* ends my_set_colors */
  782.  
  783.  
  784.  
  785.  
  786.    /*************************
  787.    *
  788.    *   NOT USED IN CIPS
  789.    *
  790.    *************************/
  791.  
  792. put_pixel(ppx, ppy, color)
  793.    int color, ppx, ppy;
  794. {
  795.  
  796. int RW_Page=0x0ff;
  797. int W_Page=0x0ff;
  798. int R_Page=0x0ff;
  799. int PAGE_SEL_PORT=0x3cd;
  800.  
  801. printf("\ny=%d x=%d color=%d Page=%d offset=%d", 
  802. ppy, ppx, color, (ppy*800
  803. + ppx)/0x10000, (ppy*800 + ppx)%0x10000);
  804.  
  805. /******************
  806.  
  807.    _asm{
  808.              ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  809.              ;
  810.              ;         taken from file
  811.              ;         d:\supervga\256col\wpixel.asm
  812.              ;
  813.              ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  814.  
  815.  
  816.         PUSH        BP     ;Preserve BP
  817.         MOV     BP,SP      ;Preserve stack pointer
  818.  
  819.         PUSH    ES         ;Preserve segment and index registers
  820.         PUSH    DS
  821.         PUSH    DI
  822.         PUSH    SI
  823.         ; Convert x,y pixel address to Page and Offset
  824.  
  825.         MOV        AX,ppy     ;Fetch y coordinate
  826.                               ;Video_Pitch=SCREEN_PITCH=800
  827.         MUL        cs:800     ;multiply by width in bytes
  828.         ADD        AX,ppx     ;add x coordinate to compute offset
  829.         ADC        DX,0       ;add overflow to upper 16 bits
  830.                               ;Graph_Seg=0aoooh
  831.         MOV        DS,CS:0a000h   ;Put new address in DS:SI
  832.         MOV        DI,AX
  833.         MOV     AL,DL             ;Copy page number into AL
  834.         JMP        Select_Page    ;Select proper page
  835. Ret_Page:
  836.  
  837.  
  838.         ; Set pixel to supplied value
  839.  
  840.         MOV        AL,color     ;Fetch color to use
  841.         MOV     [DI],AL         ;Set the pixel
  842.  
  843.         ; Clean up and return
  844.  
  845.         POP     SI       ;Restore segment and index registers
  846.         POP     DI
  847.         POP     DS
  848.         POP     ES
  849.  
  850.         MOV     SP,BP    ;Restore stack pointer
  851.         POP     BP       ;Restore BP
  852.  
  853.         JMP        The_End
  854.  
  855.  
  856. Select_Page:
  857.         CMP        AL,CS:RW_Page  ;Check if already selected
  858.         JNE        SP_Go
  859.         JMP        Ret_Page
  860. SP_Go:
  861.         PUSH        AX
  862.         PUSH        DX    MOV  DX,PAGE_SEL_PORT        ;Fetch address of page select
  863.         AND        AL,7                ;Force page number into 0-7
  864.         MOV        CS:RW_Page,AL       ;Save most recently selected page
  865.         MOV        CS:R_Page,0FFh
  866.         MOV        CS:W_Page,0FFh
  867.         MOV        AH,AL               ;Copy page into AH
  868.         SHL        AH,1                ;Shift page number
  869.         SHL        AH,1
  870.         SHL        AH,1
  871.         OR        AL,AH                ;Move page number into "write" bits
  872.         OR        AL,40h               ;Force bit 6
  873.         OUT        DX,AL               ;Write out the new page select
  874.         POP        DX
  875.         POP        AX
  876.         JMP        Ret_Page
  877.  
  878. The_End:
  879.  
  880.    }*******/        /* ends _asm */
  881.  
  882. }  /* ends put_pixel */
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.    /*******************************************
  890.    *
  891.    *   map_64_shades_of_gray()
  892.    *
  893.    *   This function maps 256 DAC registers to
  894.    *   gray shades.  Taken from p. 73 of
  895.    *   Sutty and Blair's text on superVGA
  896.    *
  897.    ********************************************/
  898.  
  899.  
  900. map_64_shades_of_gray()
  901. {
  902.  
  903.    _asm{
  904.       mov ax,0013h ;mod 13h is 320x200x256
  905.       int 10h
  906.  
  907.       mov ah,10h   ; function 10h
  908.       mov al,1bh   ; sub function 1bh
  909.       mov bx,0h    ; first DAC register to change
  910.       mov cx,100h  ; change 256 DAC registers
  911.       int 10h
  912.  
  913.    } /* ends asm */
  914. }  /* ends map_64_shades_of_gray */
  915.